{inc:header.htm}

<div class="m">
	<div class="head">
		<dl>
			<dd class="on">{$_title}</dd>
			<dd>在线获取</dd>
		</dl>
	</div>
	<div class="p c2">
		<div class="cc" id="plugin">
			{if:empty($plugins[enable]) && empty($plugins[disable]) && empty($plugins[not_install])}
				<div class="sky warning bnote" style="margin-top:8px"><i></i><b>暂无插件</b></div>
			{else}

			{loop:$plugins[enable] $v $k}
				<div class="plu cf">
					<div class="plu_l">
						<p class="plu_ico"{if:isset($v['is_show'])} style="background:url(../{$core}/plugin/{$k}/show.jpg)"{/if}></p>
					</div>
					<div class="plu_c">
						<p class="plu_cont plu_b">{$v[name]}({$k})</p>
						<p class="plu_bottom" plugin="{$k}" version="{$v[version]}">
							<a class="but2 disabled">停用</a>
							{if:!empty($v['setting'])}<a class="but2" href="javascript:parent.oneTab('{$v[setting]}');">设置</a>{/if}
						</p>
					</div>
					<div class="plu_r">
						<p class="plu_cont plu_i">{$v[brief]}</p>
						<p class="plu_bottom"><b>版本号：{$v[version]}</b> <b>作者: <a href="{$v[authorurl]}" target="_blank">{$v[author]}</a></b> <b>最近更新：{$v[update]}</b></p>
					</div>
				</div>
			{/loop}

			{loop:$plugins[disable] $v $k}
				<div class="plu cf">
					<div class="plu_l">
						<p class="plu_ico"{if:isset($v['is_show'])} style="background:url(../{$core}/plugin/{$k}/show.jpg)"{/if}></p>
					</div>
					<div class="plu_c">
						<p class="plu_cont plu_b">{$v[name]}({$k})</p>
						<p class="plu_bottom" plugin="{$k}" version="{$v[version]}">
							{if:!empty($v['setting']) && !empty($v['setting_ok'])}
							<a class="but2" href="javascript:parent.oneTab('{$v[setting]}');">设置</a>
							{else}
							<a class="but2 enable">启用</a>
							{/if}
							<a class="but2 del">删除</a>
						</p>
					</div>
					<div class="plu_r">
						<p class="plu_cont plu_i">{$v[brief]}</p>
						<p class="plu_bottom"><b>版本号：{$v[version]}</b> <b>作者: <a href="{$v[authorurl]}" target="_blank">{$v[author]}</a></b> <b>最近更新：{$v[update]}</b></p>
					</div>
				</div>
			{/loop}

			{loop:$plugins[not_install] $v $k}
				<div class="plu cf">
					<div class="plu_l">
						<p class="plu_ico"{if:isset($v['is_show'])} style="background:url(../{$core}/plugin/{$k}/show.jpg)"{/if}></p>
					</div>
					<div class="plu_c">
						<p class="plu_cont plu_b">{$v[name]}({$k})</p>
						<p class="plu_bottom" plugin="{$k}" version="{$v[version]}">
							<a class="but2 install">安装</a>
							<a class="but2 del">删除</a>
						</p>
					</div>
					<div class="plu_r">
						<p class="plu_cont plu_i">{$v[brief]}</p>
						<p class="plu_bottom"><b>版本号：{$v[version]}</b> <b>作者: <a href="{$v[authorurl]}" target="_blank">{$v[author]}</a></b> <b>最近更新：{$v[update]}</b></p>
					</div>
				</div>
			{/loop}

			{/if}
		</div>
		<div class="cc un" id="twcms_app">
			<div class="sky warning bnote"><i></i><b>玩命加载中<font id="loading">...</font></b></div>
		</div>
	</div>
</div>
<script type="text/javascript">
setPlurWidth();
$(window).resize(setPlurWidth);
$("#plugin .plu_c .plu_bottom a").each(function() {
	if(!this.href) this.href = "javascript:;";
});

//检测插件是否需要升级
setTimeout(function() {
	var plu_arr = new Array();
	$("#plugin>.plu>.plu_c>.plu_bottom").each(function(i) {
		if(i >= 20) return;
		plu_arr[i] = $(this).attr("plugin") + "-" + $(this).attr("version");
	});
	$.getScript("http://www.twcms.com/app/?go=plugin_upgrade&s="+plu_arr.join(","));
}, 1000)

//停用
$(".disabled").click(function(){
	twAjax.postd("index.php?u=plugin-disabled-ajax-1", {"dir" : $(this).parent().attr("plugin")}, function(data){
		twAjax.alert(data);
		if(window.twData.err==0) setTimeout(function(){window.location.reload();}, 1000);
	});
});

//启用
$(".enable").click(function(){
	enable($(this).parent().attr("plugin"));
});

//安装
$(".install").click(function(){
	twAjax.postd("index.php?u=plugin-install-ajax-1", {"dir" : $(this).parent().attr("plugin")}, function(data){
		twAjax.alert(data);
		if(window.twData.err==0) setTimeout(function(){window.location.reload();}, 1000);
	});
});

//删除
$(".del").click(function(){
	var dir = $(this).parent().attr("plugin");
	twAjax.confirm("删除不可恢复，确定删除“<font color='red'>"+$(this).parent().parent().children(".plu_b").html()+"</font>”？", function(){
		twAjax.postd("index.php?u=plugin-delete-ajax-1", {"dir" : dir}, function(data){
			window.twErr = true;
			twAjax.alert(data);
			$(".ajaxtips u").click(function(){window.location.reload();});
			if(window.twData.err==0) setTimeout(function(){window.location.reload();}, 1000);
		});
	});
});

//加载效果
var int;
function loading() {
	var dot = '';
	int = setInterval(function(){
		dot += '.';
		if(dot.length > 6) dot = '.';
		$("#loading").html(dot);
	}, 50);
}

//在线获取
$(".head dd:eq(1)").one("click", function() {
	loading();
	$.getScript("http://www.twcms.com/app/?go=plugin");
});

//在线安装
function install_plugin(dir) {
	twAjax.confirm("玩命下载 <font color='red'>"+dir+"</font> 中<font id='loading'>......</font>", function(){});
	loading();
	$("#okA").remove();

	$.getScript("index.php?u=plugin-install_plugin-dir-" + dir, function(){
		clearInterval(int);
		if(typeof err == 'number' && !err && $("#install_enable").length == 0) {
			$("#noA").after('<a id="install_enable" class="but3" href="javascript:;">启用</a>');
			$("#install_enable").click(function() { enable(dir); });
		}
		//只要在线安装过都重新加载一下
		$(".head dd:eq(0)").click(function(){ window.location.reload(); });
	});
}

//在线升级
function upgrade(dir) {
	twAjax.confirm("玩命下载 <font color='red'>"+dir+"</font> 中<font id='loading'>......</font>", function(){});
	loading();
	$("#okA").remove();

	$.getScript("index.php?u=plugin-upgrade-dir-" + dir, function(){
		clearInterval(int);
		$("#noA").html("我知道了");
		setTimeout(function(){window.location.reload();}, 2000);
	});
}

//设置插件展示宽度 PS: CSS3 时代的到来就可以不使用这么笨的方法了
function setPlurWidth() {
	$(".plu_r").width(Math.max(500, $(".plu:visible").width() - $(".plu_l:visible").outerWidth(true) - $(".plu_c:visible").outerWidth(true) - 15));
}

//启用
function enable(dir) {
	twAjax.postd("index.php?u=plugin-enable-ajax-1", {"dir" : dir}, function(data){
		twAjax.alert(data);
		if(window.twData.err==0) setTimeout(function(){window.location.reload();}, 1000);
	});
}
</script>
</body>
</html>
